package List;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class LinkedListmoni_ {
    public static void main(String[] args) {
        Node jack = new Node("jack");
        Node tom = new Node("tom");
        Node wyx = new Node("wyx");

        jack.next = tom;
        tom.next = wyx;
        wyx.pre = tom;
        tom.pre = jack;

        Node first = jack;
        Node last = wyx;

        while(first.data != null){
            System.out.println(first);
            if(first.next == null){
                break;
            }
                first = first.next;
        }

        System.out.println("=====从尾到头=====");
        while(last.data != null){
            System.out.println(last);
            if(last.pre == null){
                break;
            }
            last = last.pre;
        }


        //添加一个元素
        Node lihua = new Node("lihua");
        tom.next = lihua;
        lihua.next = wyx;
        wyx.pre = lihua;
        lihua.pre = tom;

        System.out.println("=====添加后=====");
        first = jack;
        while(first.data != null){
            System.out.println(first);
            if(first.next == null){
                break;
            }
            first = first.next;
        }


    }
}
class Node{
    public Object data;
    public Node next;
    public Node pre;

    public Node(Object name) {
        this.data = name;
    }

    @Override
    public String toString() {
        return "data=" + data ;

    }
}
